﻿Imports extranet.BC
Imports extranet.BE
Imports System.Collections.Generic
Imports MetodosComuns

Public Class Aux1
    Private _id As Integer
    Private _assunto As String
    Private _criador As String
    Private _totalPosts As Integer
    Private _totalVisualizacoes As Integer
    Private _visivel As String

    Public Property Id() As Integer
        Get
            Return _id
        End Get
        Set(ByVal value As Integer)
            _id = value
        End Set
    End Property
    Public Property assunto() As String
        Get
            Return _assunto
        End Get
        Set(ByVal value As String)
            _assunto = value
        End Set
    End Property
    Public Property criador() As String
        Get
            Return _criador
        End Get
        Set(ByVal value As String)
            _criador = value
        End Set
    End Property
    Public Property totalPosts() As Integer
        Get
            Return _totalPosts
        End Get
        Set(ByVal value As Integer)
            _totalPosts = value
        End Set
    End Property
    Public Property totalVisualizacoes() As Integer
        Get
            Return _totalVisualizacoes
        End Get
        Set(ByVal value As Integer)
            _totalVisualizacoes = value
        End Set
    End Property
    Public Property Visivel() As String
        Get
            Return _visivel
        End Get
        Set(ByVal value As String)
            _visivel = value
        End Set
    End Property
End Class


Partial Class forum_subcategoria
    Inherits System.Web.UI.Page
    Dim idsubcategoria As String
    Dim lstAuxiliar As List(Of Aux1)
    Dim lstAuxTopico As List(Of BETopico)
    Dim dummyAux As Aux1
    Dim objBESubcategoria As BESubcategoria
    Dim objBECategoria As BEForum

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim objBESeguranca As New BESeguranca
        Dim objBEUsuario As BEUsuario = Session("objBEUsuario")

        If IsNothing(objBEUsuario) Then Response.Redirect(TELA_LOGOUT)
        Session("strTela") = MetodosComuns.GetCurrentPageName()
        If Not IsPostBack Then          ' SEGURANÇA
            objBESeguranca = BCSeguranca.SelecionaPermissoes(objBEUsuario.GrupoAcesso, Session("strTela"))
            If Not objBESeguranca.Autorizado Then Response.Redirect(TELA_LOGOUT)
            Session("objBESeguranca") = objBESeguranca
        Else
            objBESeguranca = Session("objBESeguranca")
        End If

        lstAuxiliar = New List(Of Aux1)
        lstAuxTopico = New List(Of BETopico)

        Dim i As Integer
        If Not IsPostBack Then
            idsubcategoria = Request.QueryString("id")

            objBESubcategoria = New BESubcategoria
            objBECategoria = New BEForum
            objBESubcategoria = BCForum.SelecionaSubcategoria(idsubcategoria)
            objBECategoria = BCForum.SelecionaCategoria(objBESubcategoria.IdCategoria.ToString)
            lblCaminho.Text = objBECategoria.Nome & " >> " & objBESubcategoria.Nome
            lblTituloSubcategoria.Text = objBESubcategoria.Nome

            If objBESeguranca.Escrita Then 'Verificar aki se usuário tem permissao de administrador
                lstAuxTopico = BCForum.ListarTopicosNaoPendentes(idsubcategoria)
            Else
                lstAuxTopico = BCForum.ListarTopicosVisiveis(idsubcategoria)
                GridView1.Columns.Item(4).Visible = False
                GridView1.Columns.Item(5).Visible = False
                GridView1.Columns.Item(6).Visible = False
                GridView1.Columns(0).ItemStyle.Width = 350
            End If

            For i = 0 To lstAuxTopico.Count - 1
                dummyAux = New Aux1
                dummyAux.Id = lstAuxTopico(i).Id
                dummyAux.assunto = lstAuxTopico(i).Titulo
                dummyAux.criador = lstAuxTopico(i).MensagemTopico.Remetente
                dummyAux.totalPosts = lstAuxTopico(i).TotPosts
                dummyAux.totalVisualizacoes = lstAuxTopico(i).totVisualizacoes
                If lstAuxTopico(i).Visivel = True Then
                    dummyAux.Visivel = "Vsível"
                Else
                    dummyAux.Visivel = "Não Visível"
                End If
                lstAuxiliar.Add(dummyAux)
            Next
            GridView1.DataSource = lstAuxiliar
            GridView1.DataBind()
        End If
    End Sub

    Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LinkButton1.Click
        Response.Redirect("forum_inicial.aspx")
    End Sub

    Protected Sub lnkBtnAddTopico_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles lnkBtnAddTopico.Click
        Response.Redirect("novo_topico.aspx?id=" & Request.QueryString("id"))
    End Sub
End Class
